package com.zhs.gccs.adapter;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.guanaj.easyswipemenulibrary.EasySwipeMenuLayout;
import com.zhs.gccs.R;
import com.zhs.gccs.model.GccsTaskData;
import com.zhs.gccs.utils.OnNoDoubleClickListener;
import com.zhs.gccs.vo.AdminPeopleBean;

/**
 * Created by chengzf on 2024/7/20.
 */
public class GccsPeopleListAdapter extends BaseQuickAdapter<AdminPeopleBean, BaseViewHolder>{


    public GccsPeopleListAdapter() {
        super(R.layout.item_gccs_user_view);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, AdminPeopleBean bean) {
        holder.setText(R.id.tv_user, bean.getNickName());
        holder.setText(R.id.tv_user_remark, bean.getRemark());
        holder.setGone(R.id.view_flag, holder.getBindingAdapterPosition() != mData.size() - 1);
        EasySwipeMenuLayout esml = holder.getView(R.id.esml);
        View content = holder.getView(R.id.content);
        TextView tv_stop = holder.getView(R.id.tv_stop);
        TextView tv_delete = holder.getView(R.id.tv_delete);
        if("0".equals(bean.getStatus())){//0正常 1停用
            tv_stop.setText("停用");
        }else {
            tv_stop.setText("启用");
        }
//        holder.addOnClickListener(R.id.content);
//        holder.addOnClickListener(R.id.tv_delete);
        content.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if(operationListener!=null){
                    operationListener.onItemClick(bean);
                }
            }
        });
        tv_stop.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if(operationListener!=null){
                    operationListener.onStop(bean);
                }
                esml.resetStatus();
            }
        });
        tv_delete.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if(operationListener!=null){
                    operationListener.onDelete(bean);
                }
                esml.resetStatus();
            }
        });
    }

    private ItemOperationListener operationListener;

    public void setOperationListener(ItemOperationListener operationListener) {
        this.operationListener = operationListener;
    }

    public interface ItemOperationListener{
        void onDelete(AdminPeopleBean bean);
        void onStop(AdminPeopleBean bean);
        void onItemClick(AdminPeopleBean bean);
    }
}
